import {
  adsList,
  adsPosition,
  getAdsInfo,
  adsAdd,
  adsEdit
} from '@/api/ads'
import utils from '@/utils/common'
var timeStamp = Number(new Date())
const ads = {
  state: {},

  mutations: {},

  actions: {
    // 广告列表
    AdsList ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        clientType: data.clientType,
        flag: data.flag,
        keyword: data.keyword,
        startTime: data.startTime,
        endTime: data.endTime,
        page: data.page,
        pageSize: data.pageSize
      }
      return new Promise((resolve, reject) => {
        adsList(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 广告位列表
    AdsPositionList ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        clientType: data.clientType
      }
      console.log(loginParams)
      return new Promise((resolve, reject) => {
        adsPosition(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 广告获取
    GetAdsInfo ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id
      }
      return new Promise((resolve, reject) => {
        getAdsInfo(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 广告添加
    AdsAdd ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        clientType: data.clientType,
        postion: data.postion,
        picUrl: data.picUrl,
        flag: data.flag,
        linkType: data.linkType,
        linkUrl: data.linkUrl,
        linkArg: data.linkArg
      }
      return new Promise((resolve, reject) => {
        adsAdd(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 广告编辑
    AdsEdit ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id,
        clientType: data.clientType,
        postion: data.postion,
        picUrl: data.picUrl,
        flag: data.flag,
        linkType: data.linkType,
        linkUrl: data.linkUrl,
        linkArg: data.linkArg
      }
      return new Promise((resolve, reject) => {
        adsEdit(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }

  }
}

export default ads
